<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>拖拽图片</title>
    <style>
      .box {
        position: relative;
        height: 100px;
        width: 100px;
        border-radius: 12px;
        border: 2px solid #333;
      }
      .box .image {
        height: 100%;
        width: 100%;
        border-radius: 10px;
        background-size: cover;
        background-position: center;
        background-image: url(./img/验证图.jpg);
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="image" draggable="true"></div>
    </div>
    <div class="box"></div>
  </body>
  <script>
    const boxes = document.querySelectorAll(".box"),
      image = document.querySelector(".image");
    boxes.forEach((box) => {
      box.addEventListener("dragover", (e) => {
        e.preventDefault();
      });
      box.addEventListener("drop", () => {
        box.appendChild(image);
      });
    });
  </script>
</html>
